﻿using FastJSON;
using FineAdmin.Common;
using FineAdmin.IService;
using FineAdmin.Model;
using FineAdmin.Web.Controllers;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;

namespace FineAdmin.Web.Areas.SysSet.Controllers
{
    public class SystemParameterSetController : BaseController
    {
        // GET: SysSet/SystemParameterSet

       
        public override ActionResult Index(int? id)
        {
            base.Index(id);
            return View();
        }

        [HttpGet]
        public JsonResult List(SystemParameterModel model, PageInfo pageInfo)
        {
            var result = SystemParameterService.GetListByFilter(model, pageInfo);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        public ActionResult Add()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Add(SystemParameterModel model)
        {
            model.CreateTime = DateTime.Now;
            model.CreateUserId = Operator.UserId;
            model.UpdateTime = DateTime.Now;
            model.UpdateUserId = Operator.UserId;
            var result = SystemParameterService.Insert(model) ? SuccessTip("添加成功") : ErrorTip("添加失败");
            return Json(result);
        }

        public ActionResult Edit(int id)
        {
            var model = SystemParameterService.GetById(id);
            return View(model);
        }
        [HttpPost]
        public ActionResult Edit(SystemParameterModel model)
        {
            var oldmodel = SystemParameterService.GetById(model.Id);
            oldmodel.SPValue = model.SPValue;//只能修改值
            oldmodel.Remark = model.Remark;//只能修改值
            oldmodel.UpdateTime = DateTime.Now;
            oldmodel.UpdateUserId = Operator.UserId;

            var result = SystemParameterService.UpdateById(oldmodel) ? SuccessTip("修改成功") : ErrorTip("修改失败");
            return Json(result);
        }
    }
}